
interface dance {
    dance(): void; //接口中只能定义方法，不能定义属性
}
interface caiyi extends dance {
    caiyi(): void;
}
class Person  {  //类实现接口，必须实现接口中的所有方法
    name: string; //属性可以定义在接口中，也可以定义在类中，但是接口中定义的属性必须是public，private，protected，readonly，可选的，默认值必须是undefined
    age: number;
    constructor ( name: string,  age: number) { //构造函数可以定义在接口中，也可以定义在类中，但是接口中定义的构造函数必须是public，private，protected，readonly，可选的，默认值必须是undefined
        this.name = name;
        this.age = age;
    }
    sayHello(): void { 
        console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
    }
}
class Teacher extends Person implements caiyi { 
    subject: string; 
    constructor (name: string,  age: number, subject: string) {
        super(name, age); 
        this.subject = subject;
    }
    sayHello(): void { 
        console.log(`Hello, my name is ${this.name} and I am ${this.age} years old. I teach ${this.subject}.`);
    }
    dance(): void { 
        console.log('I am dancing!');
    }
    caiyi(): void { 
        console.log('I am caiyi!');
    }
}
class Student extends Person implements dance {
    id: number;
    constructor (id: number,name: string,  age: number,) { //构造函数可以定义在接口中，也可以定义在类中，但是接口中定义的构造函数必须是public，private，protected，readonly，可选的，默认值必须是undefined
        super(name, age);
        this.id = id;
     }
     sayHello(): void {
        console.log(`Hello,my id is ${this.id}  name is ${this.name} and I am ${this.age} years old.`);
     } //super关键字用于调用父类的构造函数，必须在子类的构造函数中调用
    dance(): void {
       console.log('I am dancing!');
    }
}
let stu1 = new Student(1,'John', 30);
stu1.sayHello(); // Hello, my name is John and I am 30 years old.
stu1.dance(); // I am dancing!
let teacher1 = new Teacher('Jane', 40, 'Math');
teacher1.sayHello(); // Hello, my name is Jane and I am 40 years old. I teach Math.
teacher1.dance(); // I am dancing!
teacher1.caiyi(); // I am caiyi!